package JS;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class JSClient {
	public static void main(String[] args) throws UnknownHostException, IOException, InterruptedException {
		Socket serverSocket = new Socket("localhost", 90);
    	ObjectOutputStream out = new ObjectOutputStream(serverSocket.getOutputStream());
        ObjectInputStream in = new ObjectInputStream(serverSocket.getInputStream());
        long time = System.currentTimeMillis();
    	for (int i = 0; i < 10000; i++) {
    		out.writeObject(SensorData.generate());
    		int j = in.read();
    		while (j == (-1)) {
    			Thread.sleep(5);
    			j = in.read();
    		}
    	}
    	System.out.println("throughput = "+1d * (System.currentTimeMillis() - time)/10000);
    	long timeDelay = System.currentTimeMillis();
    	out.writeObject(SensorData.generate());
    	int j = in.read();
		while (j == (-1)) {
			Thread.sleep(5);
			j = in.read();
		}
		System.out.println("delay = "+(System.currentTimeMillis() - timeDelay));
    	serverSocket.close();
	}
}
